package com.wn;

import com.wn.service.IUserService;
import com.wn.service.impl.UserServiceImpl;
import sun.misc.ProxyGenerator;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ProxyUtils{
	
	public static void main(String[] args) throws Exception {
        saveProxyFile();
    }
	
	private static void saveProxyFile() throws IOException {

        IUserService userService = new UserServiceImpl();

        FileOutputStream out = null;
        File file = new File("C:\\test\\" + "$Proxy0.class");
        file.createNewFile();
        try {
            byte[] classFile = ProxyGenerator.generateProxyClass(
			"$Proxy0",
                    userService.getClass().getInterfaces());
            out = new FileOutputStream(file);
            out.write(classFile);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.flush();
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

